home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue39 / construc / VISITORX.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1998-10-06  |  11.6 KB  |  445 lines

  1. unit VisitorX;
  2. // 194.229.217.93
  3. interface
  4. uses
  5.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  6.   ActiveX, AxCtrls, VisitBob_TLB, Db, ExtCtrls, Grids, DBGrids, StdCtrls, Buttons,
  7.   DBClient;
  8.  
  9. type
  10.   TVisitorTrackingX = class(TActiveForm, IVisitorTrackingX)
  11.     Panel1: TPanel;
  12.     ClientDataSet1: TClientDataSet;
  13.     DataSource1: TDataSource;
  14.     DBGrid1: TDBGrid;
  15.     BitBtnConnect: TBitBtn;
  16.     BitBtnPaths: TBitBtn;
  17.     BitBtnStats: TBitBtn;
  18.     procedure BitBtnConnectClick(Sender: TObject);
  19.     procedure DBGrid1DblClick(Sender: TObject);
  20.     procedure DBGrid1CellClick(Column: TColumn);
  21.     procedure BitBtnPathsClick(Sender: TObject);
  22.     procedure BitBtnStatsClick(Sender: TObject);
  23.     procedure FormCreate(Sender: TObject);
  24.   private
  25.     { Private declarations }
  26.     FEvents: IVisitorTrackingXEvents;
  27.     procedure ActivateEvent(Sender: TObject);
  28.     procedure ClickEvent(Sender: TObject);
  29.     procedure CreateEvent(Sender: TObject);
  30.     procedure DblClickEvent(Sender: TObject);
  31.     procedure DeactivateEvent(Sender: TObject);
  32.     procedure DestroyEvent(Sender: TObject);
  33.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  34.     procedure PaintEvent(Sender: TObject);
  35.   protected
  36.     { Protected declarations }
  37.     procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
  38.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  39.     function Get_Active: WordBool; safecall;
  40.     function Get_AutoScroll: WordBool; safecall;
  41.     function Get_AutoSize: WordBool; safecall;
  42.     function Get_AxBorderStyle: TxActiveFormBorderStyle; safecall;
  43.     function Get_BiDiMode: TxBiDiMode; safecall;
  44.     function Get_Caption: WideString; safecall;
  45.     function Get_Color: OLE_COLOR; safecall;
  46.     function Get_Cursor: Smallint; safecall;
  47.     function Get_DoubleBuffered: WordBool; safecall;
  48.     function Get_DropTarget: WordBool; safecall;
  49.     function Get_Enabled: WordBool; safecall;
  50.     function Get_Font: IFontDisp; safecall;
  51.     function Get_HelpFile: WideString; safecall;
  52.     function Get_KeyPreview: WordBool; safecall;
  53.     function Get_PixelsPerInch: Integer; safecall;
  54.     function Get_PrintScale: TxPrintScale; safecall;
  55.     function Get_Scaled: WordBool; safecall;
  56.     function Get_Visible: WordBool; safecall;
  57.     procedure _Set_Font(const Value: IFontDisp); safecall;
  58.     procedure Set_AutoScroll(Value: WordBool); safecall;
  59.     procedure Set_AutoSize(Value: WordBool); safecall;
  60.     procedure Set_AxBorderStyle(Value: TxActiveFormBorderStyle); safecall;
  61.     procedure Set_BiDiMode(Value: TxBiDiMode); safecall;
  62.     procedure Set_Caption(const Value: WideString); safecall;
  63.     procedure Set_Color(Value: OLE_COLOR); safecall;
  64.     procedure Set_Cursor(Value: Smallint); safecall;
  65.     procedure Set_DoubleBuffered(Value: WordBool); safecall;
  66.     procedure Set_DropTarget(Value: WordBool); safecall;
  67.     procedure Set_Enabled(Value: WordBool); safecall;
  68.     procedure Set_Font(var Value: IFontDisp); safecall;
  69.     procedure Set_HelpFile(const Value: WideString); safecall;
  70.     procedure Set_KeyPreview(Value: WordBool); safecall;
  71.     procedure Set_PixelsPerInch(Value: Integer); safecall;
  72.     procedure Set_PrintScale(Value: TxPrintScale); safecall;
  73.     procedure Set_Scaled(Value: WordBool); safecall;
  74.     procedure Set_Visible(Value: WordBool); safecall;
  75.   public
  76.     { Public declarations }
  77.     procedure Initialize; override;
  78.   end;
  79.  
  80. implementation
  81. uses
  82.   ComObj, ComServ;
  83.  
  84. {$R *.DFM}
  85.  
  86. { TVisitorTrackingX }
  87.  
  88. procedure TVisitorTrackingX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
  89. begin
  90.   { Define property pages here.  Property pages are defined by calling
  91.     DefinePropertyPage with the class id of the page.  For example,
  92.       DefinePropertyPage(Class_VisitorTrackingXPage); }
  93. end;
  94.  
  95. procedure TVisitorTrackingX.EventSinkChanged(const EventSink: IUnknown);
  96. begin
  97.   FEvents := EventSink as IVisitorTrackingXEvents;
  98. end;
  99.  
  100. procedure TVisitorTrackingX.Initialize;
  101. begin
  102.   inherited Initialize;
  103.   OnActivate := ActivateEvent;
  104.   OnClick := ClickEvent;
  105.   OnCreate := CreateEvent;
  106.   OnDblClick := DblClickEvent;
  107.   OnDeactivate := DeactivateEvent;
  108.   OnDestroy := DestroyEvent;
  109.   OnKeyPress := KeyPressEvent;
  110.   OnPaint := PaintEvent;
  111. end;
  112.  
  113. function TVisitorTrackingX.Get_Active: WordBool;
  114. begin
  115.   Result := Active;
  116. end;
  117.  
  118. function TVisitorTrackingX.Get_AutoScroll: WordBool;
  119. begin
  120.   Result := AutoScroll;
  121. end;
  122.  
  123. function TVisitorTrackingX.Get_AutoSize: WordBool;
  124. begin
  125.   Result := AutoSize;
  126. end;
  127.  
  128. function TVisitorTrackingX.Get_AxBorderStyle: TxActiveFormBorderStyle;
  129. begin
  130.   Result := Ord(AxBorderStyle);
  131. end;
  132.  
  133. function TVisitorTrackingX.Get_BiDiMode: TxBiDiMode;
  134. begin
  135.   Result := Ord(BiDiMode);
  136. end;
  137.  
  138. function TVisitorTrackingX.Get_Caption: WideString;
  139. begin
  140.   Result := WideString(Caption);
  141. end;
  142.  
  143. function TVisitorTrackingX.Get_Color: OLE_COLOR;
  144. begin
  145.   Result := OLE_COLOR(Color);
  146. end;
  147.  
  148. function TVisitorTrackingX.Get_Cursor: Smallint;
  149. begin
  150.   Result := Smallint(Cursor);
  151. end;
  152.  
  153. function TVisitorTrackingX.Get_DoubleBuffered: WordBool;
  154. begin
  155.   Result := DoubleBuffered;
  156. end;
  157.  
  158. function TVisitorTrackingX.Get_DropTarget: WordBool;
  159. begin
  160.   Result := DropTarget;
  161. end;
  162.  
  163. function TVisitorTrackingX.Get_Enabled: WordBool;
  164. begin
  165.   Result := Enabled;
  166. end;
  167.  
  168. function TVisitorTrackingX.Get_Font: IFontDisp;
  169. begin
  170.   GetOleFont(Font, Result);
  171. end;
  172.  
  173. function TVisitorTrackingX.Get_HelpFile: WideString;
  174. begin
  175.   Result := WideString(HelpFile);
  176. end;
  177.  
  178. function TVisitorTrackingX.Get_KeyPreview: WordBool;
  179. begin
  180.   Result := KeyPreview;
  181. end;
  182.  
  183. function TVisitorTrackingX.Get_PixelsPerInch: Integer;
  184. begin
  185.   Result := PixelsPerInch;
  186. end;
  187.  
  188. function TVisitorTrackingX.Get_PrintScale: TxPrintScale;
  189. begin
  190.   Result := Ord(PrintScale);
  191. end;
  192.  
  193. function TVisitorTrackingX.Get_Scaled: WordBool;
  194. begin
  195.   Result := Scaled;
  196. end;
  197.  
  198. function TVisitorTrackingX.Get_Visible: WordBool;
  199. begin
  200.   Result := Visible;
  201. end;
  202.  
  203. procedure TVisitorTrackingX._Set_Font(const Value: IFontDisp);
  204. begin
  205.   SetOleFont(Font, Value);
  206. end;
  207.  
  208. procedure TVisitorTrackingX.Set_AutoScroll(Value: WordBool);
  209. begin
  210.   AutoScroll := Value;
  211. end;
  212.  
  213. procedure TVisitorTrackingX.Set_AutoSize(Value: WordBool);
  214. begin
  215.   AutoSize := Value;
  216. end;
  217.  
  218. procedure TVisitorTrackingX.Set_AxBorderStyle(
  219.   Value: TxActiveFormBorderStyle);
  220. begin
  221.   AxBorderStyle := TActiveFormBorderStyle(Value);
  222. end;
  223.  
  224. procedure TVisitorTrackingX.Set_BiDiMode(Value: TxBiDiMode);
  225. begin
  226.   BiDiMode := TBiDiMode(Value);
  227. end;
  228.  
  229. procedure TVisitorTrackingX.Set_Caption(const Value: WideString);
  230. begin
  231.   Caption := TCaption(Value);
  232. end;
  233.  
  234. procedure TVisitorTrackingX.Set_Color(Value: OLE_COLOR);
  235. begin
  236.   Color := TColor(Value);
  237. end;
  238.  
  239. procedure TVisitorTrackingX.Set_Cursor(Value: Smallint);
  240. begin
  241.   Cursor := TCursor(Value);
  242. end;
  243.  
  244. procedure TVisitorTrackingX.Set_DoubleBuffered(Value: WordBool);
  245. begin
  246.   DoubleBuffered := Value;
  247. end;
  248.  
  249. procedure TVisitorTrackingX.Set_DropTarget(Value: WordBool);
  250. begin
  251.   DropTarget := Value;
  252. end;
  253.  
  254. procedure TVisitorTrackingX.Set_Enabled(Value: WordBool);
  255. begin
  256.   Enabled := Value;
  257. end;
  258.  
  259. procedure TVisitorTrackingX.Set_Font(var Value: IFontDisp);
  260. begin
  261.   SetOleFont(Font, Value);
  262. end;
  263.  
  264. procedure TVisitorTrackingX.Set_HelpFile(const Value: WideString);
  265. begin
  266.   HelpFile := String(Value);
  267. end;
  268.  
  269. procedure TVisitorTrackingX.Set_KeyPreview(Value: WordBool);
  270. begin
  271.   KeyPreview := Value;
  272. end;
  273.  
  274. procedure TVisitorTrackingX.Set_PixelsPerInch(Value: Integer);
  275. begin
  276.   PixelsPerInch := Value;
  277. end;
  278.  
  279. procedure TVisitorTrackingX.Set_PrintScale(Value: TxPrintScale);
  280. begin
  281.   PrintScale := TPrintScale(Value);
  282. end;
  283.  
  284. procedure TVisitorTrackingX.Set_Scaled(Value: WordBool);
  285. begin
  286.   Scaled := Value;
  287. end;
  288.  
  289. procedure TVisitorTrackingX.Set_Visible(Value: WordBool);
  290. begin
  291.   Visible := Value;
  292. end;
  293.  
  294. procedure TVisitorTrackingX.ActivateEvent(Sender: TObject);
  295. begin
  296.   if FEvents <> nil then FEvents.OnActivate;
  297. end;
  298.  
  299. procedure TVisitorTrackingX.ClickEvent(Sender: TObject);
  300. begin
  301.   if FEvents <> nil then FEvents.OnClick;
  302. end;
  303.  
  304. procedure TVisitorTrackingX.CreateEvent(Sender: TObject);
  305. begin
  306.   if FEvents <> nil then FEvents.OnCreate;
  307. end;
  308.  
  309. procedure TVisitorTrackingX.DblClickEvent(Sender: TObject);
  310. begin
  311.   if FEvents <> nil then FEvents.OnDblClick;
  312. end;
  313.  
  314. procedure TVisitorTrackingX.DeactivateEvent(Sender: TObject);
  315. begin
  316.   if FEvents <> nil then FEvents.OnDeactivate;
  317. end;
  318.  
  319. procedure TVisitorTrackingX.DestroyEvent(Sender: TObject);
  320. begin
  321.   if FEvents <> nil then FEvents.OnDestroy;
  322. end;
  323.  
  324. procedure TVisitorTrackingX.KeyPressEvent(Sender: TObject; var Key: Char);
  325. var
  326.   TempKey: Smallint;
  327. begin
  328.   TempKey := Smallint(Key);
  329.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  330.   Key := Char(TempKey);
  331. end;
  332.  
  333. procedure TVisitorTrackingX.PaintEvent(Sender: TObject);
  334. begin
  335.   if FEvents <> nil then FEvents.OnPaint;
  336. end;
  337.  
  338.  
  339. const
  340.   F_DT = 0; { date/time }
  341.   F_IP = 1; { IP-address }
  342.   F_UA = 2; { User Agent }
  343.   F_URL = 3; { current URL }
  344.   F_REF = 4; { referrer }
  345.  
  346. procedure TVisitorTrackingX.FormCreate(Sender: TObject);
  347. begin
  348. {$IFDEF LIVE}
  349.   ClientDataSet1.RemoteServer := DCOMConnection1;
  350.   ClientDataSet1.ProviderName := 'Provider1'
  351. {$ENDIF}
  352. end;
  353.  
  354. procedure TVisitorTrackingX.BitBtnConnectClick(Sender: TObject);
  355. begin
  356.   if (Sender as TBitBtn).Caption = '&Connect' then
  357.   begin
  358.     (Sender as TBitBtn).Caption := '&Disconnect';
  359.   {$IFDEF LIVE}
  360.     DCOMConnection1.Connected := True;
  361.   {$ENDIF}
  362.     ClientDataSet1.Active := True
  363.   end
  364.   else { disconnect }
  365.   begin
  366.     ClientDataSet1.Active := False;
  367.   {$IFDEF LIVE}
  368.     DCOMConnection1.Connected := False;
  369.   {$ENDIF}
  370.     (Sender as TBitBtn).Caption := '&Connect'
  371.   end;
  372.   BitBtnPaths.Enabled := ClientDataSet1.Active;
  373.   BitBtnStats.Enabled := ClientDataSet1.Active
  374. end;
  375.  
  376. var
  377.   ColumnTitleCaption: String;
  378.  
  379. procedure TVisitorTrackingX.DBGrid1CellClick(Column: TColumn);
  380. begin
  381.   ColumnTitleCaption := Column.Title.Caption
  382. end;
  383.  
  384. procedure TVisitorTrackingX.DBGrid1DblClick(Sender: TObject);
  385. begin
  386.   ClientDataSet1.IndexFieldNames :=
  387.     ColumnTitleCaption + ';DateTime'
  388. end;
  389.  
  390. procedure TVisitorTrackingX.BitBtnPathsClick(Sender: TObject);
  391. begin
  392.   if ClientDataSet1.Filtered then
  393.   begin
  394.     DBGrid1.Columns[F_UA].Visible := True;
  395.     ClientDataSet1.Filtered := False
  396.   end
  397.   else
  398.   begin
  399.     ClientDataSet1.Filter := 'IP = ' +
  400.       ClientDataSet1.FieldByName('IP').AsString;
  401.     DBGrid1.Columns[F_UA].Visible := False;
  402.     ClientDataSet1.Filtered := True
  403.   end
  404. end;
  405.  
  406. procedure TVisitorTrackingX.BitBtnStatsClick(Sender: TObject);
  407. var
  408.   Info,UserAgent: String;
  409.   i: Integer;
  410. begin
  411.   Info := '';
  412.   ClientDataSet1.IndexFieldNames := 'UserAgent;DateTime';
  413.   UserAgent := '';
  414.   i := 0;
  415.   ClientDataSet1.First;
  416.   while not ClientDataSet1.Eof do
  417.   begin
  418.     if ClientDataSet1.Fields[F_UA].AsString <> UserAgent then
  419.     begin
  420.       if (i > 0) and (Length(UserAgent) < 88) then
  421.         Info := Info + IntToStr(i)+' - '+UserAgent + #13#10;
  422.       if Pos('MS ',ClientDataSet1.Fields[F_UA].AsString) > 0 then
  423.         Info := Info + #13#10; { entire new browser type }
  424.       i := 1; { first time this browser is used }
  425.       UserAgent := ClientDataSet1.Fields[F_UA].AsString
  426.     end
  427.     else Inc(i);
  428.     ClientDataSet1.Next { don't forget this statement!! }
  429.   end;
  430.   ClientDataSet1.First;
  431.   MessageDlg(Info,mtInformation,[mbOk],0)
  432. end;
  433.  
  434. initialization
  435.   TActiveFormFactory.Create(
  436.     ComServer,
  437.     TActiveFormControl,
  438.     TVisitorTrackingX,
  439.     Class_VisitorTrackingX,
  440.     1,
  441.     '',
  442.     OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
  443.     tmApartment);
  444. end.
  445.